package com.yc.api2;

import java.util.Random;
import java.util.UUID;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/11/1
 * Email haijunzhou@hnit.edu.cn
 */
public class RandomDemo {

    public static void main(String[] args) {
        System.out.println("Math.random() = " + Math.random());
        // 程序的随机是伪随机, 相同的随机种子将产生相同的随机序列值
        Random random1 = new Random(1);
        Random random2 = new Random(1);

        System.out.println("random1.nextInt() = " + random1.nextInt());
        System.out.println("random1.nextInt() = " + random1.nextInt());
        System.out.println("random1.nextInt() = " + random1.nextInt());
        System.out.println("=======================");
        System.out.println("random2.nextInt() = " + random2.nextInt());
        System.out.println("random2.nextInt() = " + random2.nextInt());
        System.out.println("random2.nextInt() = " + random2.nextInt());
        System.out.println("=======================");

        for (int i = 0; i < 100; i++) {
            System.out.println("random1.nextInt(101) = " + random1.nextInt(101));
        }
        //  int 最小值 和 最大值之间的随机值
        // 生成随机值的平均值在 0 附近
        // 一定会有重复值, 1/2^32
        random1.nextInt();

        // 随机生成UUID
        // 理论上说, 全时间所有电脑同时不停生成, 几千年才会生成一个重复值
        UUID uuid = UUID.randomUUID();
        System.out.println("uuid.toString() = " + uuid.toString());

    }
}

